import React, { Fragment } from 'react';
import cn from 'classnames';
import { Card } from 'antd';
import PageRouter from '@/components/PageRouter/PageRouter';
import PageHeaderWrapper from '../PageHeaderWrapper';
import styles from './QueryPage.less';

const QueryPage = ({
    form,
    table,
    children,
    routeType,
    extraButton,
    searchBoxStyle = styles.searchBox,

    ...rest
}) => {
    const content = (
        <div className={styles.container} {...rest}>
            {children || (
                <Fragment>
                    <div className={cn('form-box', searchBoxStyle)}>{form}</div>
                    {table && (
                        <Card className={styles.queryPage_table} bordered={false}>
                            {table}
                        </Card>
                    )}
                </Fragment>
            )}
        </div>
    );
    if (routeType) {
        return (
            <PageHeaderWrapper type="success">
                <PageRouter type={routeType} extraButton={extraButton}>
                    {content}
                </PageRouter>
            </PageHeaderWrapper>
        );
    }
    return <PageHeaderWrapper type="success">{content}</PageHeaderWrapper>;
};

export default QueryPage;
